Why are Java primitive types' modifiers `public`, `abstract`, & `final`?
Posted
by
oconnor0
on Stack Overflow
See other posts from Stack Overflow
or by oconnor0
Published on 2012-11-01T15:46:30Z
Indexed on
2012/11/01
17:01 UTC
Read the original article
Hit count: 191
java
|reflection
In the process of doing some reflection on Java types, I came across an oddity that I do not understand.
Inspecting int
for its modifiers returns public
, abstract
, and final
. I understand public
and final
, but the presence of abstract
on a primitive type is non-obvious to me. Why is this the case?
Edit: I am not reflecting on Integer
but on int
:
import java.lang.reflect.Modifier;
public class IntegerReflection {
public static void main(final String[] args) {
System.out.println(String.format("int.class == Integer.class -> %b", int.class == Integer.class));
System.out.println(String.format("int.class modifiers: %s", Modifier.toString(int.class.getModifiers())));
System.out.println(String.format("Integer.class modifiers: %s", Modifier.toString(Integer.class.getModifiers())));
}
}
The output when run:
int.class == Integer.class -> false
int.class modifiers: public abstract final
Integer.class modifiers: public final
© Stack Overflow or respective owner